<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_cal.tpl'}-->
    <title>商品组合</title>
</head>
<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="container">

    <!--{include file='comm/menu.tpl'}-->
	
    <div class="comm_content">
        
		    <div class="search-box">
		        <div style="position:relative">
		            <form id="search_form" onsubmit="return false;">
		                <table style="width:100%;">
		                    <tbody>
		                    <tr>
		                        <td height="27px">
		                            主商品编号：
		                            <input type="text" name="product_code" id="product_code" value="">
		
		                            &nbsp;&nbsp;
		
		                            有效期：
		                            <input type="text" style="width: 100px;" id="date" name="date" value="" class="clear" readonly="readonly" style="height:26px;">
		
		                            &nbsp;&nbsp;
		
		                            状态：
		                            <select name="useFlg" id="useFlg" style="width: 100px;">
		                                <option value="-1" selected="">请选择</option>
		                                <option value="0" >禁用</option>
		                                <option value="1" >启用</option>
		                            </select>
		
		                            &nbsp;&nbsp;
		
		                            <input type="button" class="btn" value="搜索" id="searchBtn" onclick="goodsRecommend.search();">
		                            <input type="button" class="btn" value="重置" id="searchBtn" onclick="goodsRecommend.clearUp();">
		                        </td>
		                    </tr>
		                    </tbody>
		                </table>
		            </form>
		        </div>
		    </div>
		
		    <table id="flex" style="display:none"></table>
		    
        </div>


</div>

<script type="text/javascript">

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/promotion/goodsRecommend.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            {display: "操作", width : 100, align: 'center'},
            {display: "序号", width : 100, align: 'left'},
            {display: "商品编号", width : 150, name : "recom_id", sortable : true , align: 'left'},
            {display: "商品名称", width : 450 , align: 'left'},
            {display: "起始日期", width : 120 , align: 'center'},
            {display: "结束日期", width : 120 , align: 'center'},
            {display: "使用状态", width : 80, align: 'center'}
        ],
        buttons : [
            {name: "添加", bclass: "add", onpress : "goodsRecommend.add"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "goodsRecommend.delcheck"}
        ],
        sortname: "recom_id",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var goodsRecommend = {

        delArr: new Array(),

        recom_id:'',

        useFlg:'',

        //删除确认
        delcheck: function(){
            //获取选中的行的行数
            var selected_count = $('.trSelected',flex).length;
            if (selected_count==0) {
                E.alert('请选择要删除的商品推荐');
                return;
            }else{
                var tempArr = new Array();
                for(var i=0; i<selected_count; i++){
                    var recom_idStr = $('.trSelected',flex).eq(i).attr('id');
                    var recom_id = recom_idStr.substr(3);
                    tempArr.push(recom_id);
                }
                this.delArr = tempArr;

                //弹出确认层
                E.confirm('确认删除这 ' + $('.trSelected',flex).length + ' 个商品推荐吗?', "goodsRecommend.del");
            }

        },

        del:function(){
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/promotion/goodsRecommend.ajax?operFlg=3",
                dataType: "JSON",
                data:{delArr: goodsRecommend.delArr},
                success: function(result_obj){
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "goodsRecommend.load");
                    }
                    else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //搜索
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        clearUp:function(){
            $("#date").val('');
            $("#product_code").val('');
            $("#useFlg").val(-1);
        },

        //添加
        add: function() {
            E.open("/quanliadmin/app/promotion/goodsRecommend.pscript?operFlg=2" , "", {height: 600,width: 1100, top: 50, left: 150});
        },

        //编辑
        edit: function(recom_id) {
            E.open("/quanliadmin/app/promotion/goodsRecommend.pscript?operFlg=3&id=" + recom_id , "", {height: 600,width: 1100, top: 50, left: 150} );
        },

        //详情
        detail: function(recom_id) {
            E.open("/quanliadmin/app/promotion/goodsRecommend.pscript?operFlg=4&id=" + recom_id , "", {height: 500,width: 1100, top: 50, left: 150} );
        },

        //禁用启用确认
        changeConfirm: function(recom_id , flg) {

            this.recom_id = recom_id;
            this.useFlg   = flg;

            if( flg == 0 ){
                E.confirm("您确认 启用 吗？", "goodsRecommend.change");
            }else{
                E.confirm("您确认 禁用 吗？", "goodsRecommend.change");
            }

        },

        //禁用启用
        change: function() {
            jquery_ajax(4 , {recom_id:this.recom_id,flg:this.useFlg} , goodsRecommend.callback );
        },


        //回调函数
        callback: function( obj ) {

            if( obj.code == 200 ){
                E.alert( obj.message , 2 , 'goodsRecommend.load');
            }else{
                E.alert(obj.message);
            }

        },

        load: function() {
            $("#flex").flexReload();
        }

    };


    function jquery_ajax(flg,data,func){
        $.ajax({
            type: "post",
            url: "/invokingAjax-backend/promotion/goodsRecommend.ajax?operFlg="+flg,
            dataType: "json",
            data: data,
            success: function( result_obj ) {
                func(result_obj);
            },
            error : function(msg){
                alert('网络不给力，请重新尝试...');
            }
        });
    }

    //日期控件JS
    $('#date').datetimepicker();

</script>

</body>

</html>
